//
//  WSGLoginRegisterView.m
//  oneDollar
//
//  Created by Laki on 16/6/15.
//  Copyright © 2016年 com.Laki.corder. All rights reserved.
//

#import "WSGLoginRegisterView.h"

@interface WSGLoginRegisterView()
/** 登录注册按钮*/
@property (weak, nonatomic) IBOutlet UIButton *loginRegiterBtn;

@end

@implementation WSGLoginRegisterView

#pragma mark --------------------
#pragma mark 快速创建视图
/*
 * 快速创建登录视图
 */
+ (instancetype)loginView{
    return [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil].firstObject;
}

/*
 * 快速创建注册视图
 */
+ (instancetype)regiterView{
    return [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil].lastObject;
}

- (void)awakeFromNib{
    [self setButtonImage];
}

#pragma mark --------------------
#pragma mark 设置按钮背景图片不被拉伸
- (void)setButtonImage{
    // 获取当前背景图片
    UIImage *image = self.loginRegiterBtn.currentBackgroundImage;

    // 设置从中心点进行拉伸
    image = [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5];
    
    // 给按钮设置背景图片
    [self.loginRegiterBtn setBackgroundImage:image forState:UIControlStateNormal];
    
    // 创建高亮背景图片
    UIImage *highlightImage = [UIImage imageNamed:@"RedButtonPressed"];
    
    // 设置从中心点进行拉伸
    highlightImage = [highlightImage stretchableImageWithLeftCapWidth:highlightImage.size.width * 0.5 topCapHeight:highlightImage.size.height * 0.5];
    
    // 给按钮设置背景图片
    [self.loginRegiterBtn setBackgroundImage:highlightImage forState:UIControlStateHighlighted];
}

#pragma mark --------------------
#pragma mark 通知

- (IBAction)loginRegiter {
    // 发送通知改变注册登录位置
    [[NSNotificationCenter defaultCenter] postNotificationName:WSGLoginRegisterViewNotification object:WSGLoginRegisterViewNotification];
}


@end
